package com.ziyun.erp.modules.goods.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ziyun.erp.modules.goods.dao.GoodsOptionDao;
import com.ziyun.erp.modules.goods.entity.GoodsOptionEntity;
import com.ziyun.erp.modules.goods.service.GoodsOptionService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


@Service("goodsOptionService")
public class GoodsOptionServiceImpl extends ServiceImpl<GoodsOptionDao, GoodsOptionEntity> implements GoodsOptionService {

    @Autowired
    private GoodsOptionDao goodsOptionDao;

    @Override
//    @DataSource(name = DataSourceNames.SECOND)
    public PageUtils queryPage(Map<String, Object> params) {
        Page<GoodsOptionEntity> page = this.selectPage(
                new Query<GoodsOptionEntity>(params).getPage(),
                new EntityWrapper<GoodsOptionEntity>()
        );

        return new PageUtils(page);
    }

    @Override
//    @DataSource(name = DataSourceNames.SECOND)
    @Transactional(rollbackFor = Exception.class)
    public void flagDeleteByOptionId(Long optionId) {
        goodsOptionDao.flagDeleteByOptionId(optionId);
    }

    @Override
//    @DataSource(name = DataSourceNames.SECOND)
    @Transactional(rollbackFor = Exception.class)
    public void updateValues(GoodsOptionEntity goodsOption) {
        goodsOptionDao.updateValues(goodsOption);
    }

    @Override
    public List<GoodsOptionEntity> loadTempOptionsByAttributeId(Long attributeId) {
        return this.baseMapper.loadTempOptionsByAttributeId(attributeId);
    }

}
